
/**
 * 是否可以发起收油判断
 * @returns
 */
var hreftype=0//0发起1主页
function loginjudge(){
	if(getCookie("mobiletokenuser")==""){
		location.href="../weixinuser/login.jsp"
		/*noheardspopup("#popupwindows","auto","auto")*/
	}else{
		location.href="../weixinuser/establish.jsp"
	}

}
/**
 * 获取验证码
 * @returns
 */
var count = 60;
var getCaptchaForFactorytype=0;
function getCaptchaForFactory(){
	var mobile = $("#mobile").val();
	var json = {}
	var index = layer.load(2, {
		shade: [0.5, '#fff'],
		time: 3000
	});
	if(count==60){
		if(!mobile.match(/^1[34578]\d{9}$/)) {
			layer.msg('输入有效的手机号');
			/* tippopup("#mobile","输入有效的手机号")*/
		}else{
			if(getCookie("loginGetSingleOpenIdtype")){
				var data= httpget(''+httpipstr+'alfa-mobile-ws/rest/user/getCaptchaForFactoryForLogin/' + mobile + '');
				if (data.status == "failure") {
					layer.closeAll();
					if(data.message=="4"){
						layer.msg('手机号不存在,请确认手机号');
						/* tippopup("#mobile","手机号不存在,请确认手机号")*/
					}if(data.message=="2"){
						layer.msg('角色收运人员,不能获取手机验证码');
						/* tippopup("#mobile","角色收运人员,不能获取手机验证码")*/
					}if(data.message=="1"){
						//layer.msg('已超时,请稍后重新发送');
						layer.msg('角色收运人员,不能获取手机验证码');
						/* tippopup("#mobile","信息发送失败")*/
					}
				} else {
					if(data.message=="3"){
						getCaptchaForFactorytype=0
					}
					if(data.message=="30"){
						getCaptchaForFactorytype=1
					}
					layer.closeAll();
					var countdown = setInterval(CountDown, 1000);
					function CountDown() {
						$('.send').addClass("layui-btn-disabled").css("background-color","#f1f1f1").attr('disabled',"true"); //将DIV标签隐藏。
						$('.send').css("color","#000000"); //将DIV标签隐藏。
						$('.send').html("重新发送(" + count + ")");
						if (count == 0) {
							$('.send').removeClass("layui-btn-disabled").css("background-color","#FEC61B").removeAttr("disabled"); //将DIV标签隐藏。
							$('.send').css("color","#ffffff"); //将DIV标签隐藏。
							$('.send').html("发送验证码");
							clearInterval(countdown);
						}
						count--;
					}
				}
			}else{
				tippopup("#mobile","一个微信号只能登陆一个账号")
			}
			
		}
	}else{
		
	}
	
}
function companylogin(){
	var index = layer.load(2, {
		shade: [0.2, '#fff'],
		time: 3000
	});
	if(getCookie("loginGetSingleOpenIdtype")){
		var mobile = encode64($("#mobile").val());
		var captchanum = encode64($("#captchanum").val());
		if(getCaptchaForFactorytype=="0"){
			var json = {
					"mobile": "" + mobile + "",
					"captcha": "" + captchanum + "",
					"openid":""+getCookie("openid")+"",
					"logintype":""+encode64("10")+""
				}
				setcookie("useriphone", $("#mobile").val(), 30, "/");
				$.ajax({
					cache: false,
					type: "post",
					datatype: 'json',
					contentType: 'application/json;charset=UTF-8',
					url: ''+httpipstr+'alfa-mobile-ws/rest/user/loginforweixin',
					data: JSON.stringify(json),
					success: function(data) {
						if (data.message=="7") {
							if(data.data.roleId=="10"){
								setcookie("mobiletokenuser", data.data.mobiletoken, 300, "/");
								setcookie("username", data.data.username, 300, "/");
								setcookie("realname", data.data.realname, 300, "/");
								setcookie("orgname", data.data.orgname, 300, "/");
								setcookie("userid", data.data.userId, 300, "/");
								setcookie("address", data.data.address, 300, "/");
									//触发事件
								layer.closeAll();
								if(hreftype==0){
									location.href="../weixinuser/establish.jsp"
								}else if(hreftype==1){
									location.href="../weixinuser/data.jsp"
								}
							}else{
								layer.msg('您的角色不正确，无法登录');
								/* tippopup("#mobile","您的角色不正确，无法登录")*/
							}
							
							 /*tippopup("#mobile","成功")*/
						} else {
							if(data.message=="1"){
								layer.msg('服务器异常，请联系管理员。');
								/* tippopup("#mobile","服务器异常，请联系管理员。")*/
							}else if(data.message=="2"){
								layer.msg('请输入手机号和验证码。');
								 /*tippopup("#captchanum","请输入手机号和验证码。")*/
							}else if(data.message=="3"){
								layer.msg('验证码不正确');
								/*tippopup("#captchanum","验证码不正确。")*/
							}else if(data.message=="4"){
								layer.msg('验证码已经超过有效时间。');
								/*tippopup("#captchanum","验证码已经超过有效时间。")*/
							}else if(data.message=="5"){
								layer.msg('帐号不存在');
								/*tippopup("#mobile","帐号不存在")*/
							}
							else if(data.message=="15"){
								layer.msg('您的角色不正确，无法登录');
								/* tippopup("#mobile","您的角色不正确，无法登录")*/
								}else if(data.message=="10"){
									layer.msg('管理员审核中，请稍等');
							}
						}

					}
				});
		}else{
			var json = {
					"mobile": "" + $("#mobile").val() + "",
					"captcha": "" + $("#captchanum").val() + "",
				}
				$.ajax({
					cache: false,
					type: "post",
					datatype: 'json',
					contentType: 'application/json;charset=UTF-8',
					url: ''+httpipstr+'alfa-mobile-ws/rest/user/createUser',
					data: JSON.stringify(json),
					success: function(data) {
						if(data.message=="2"){layer.msg('验证码不正确');}
						if(data.message=="4"){layer.msg('账号注册成功，请保持手机畅通');getCaptchaForFactorytype=0}
						if(data.message=="5"){layer.msg('注册失败');}
						if(data.message=="6"){layer.msg('验证码已经超过有效时间');}
					}
				});
			
		}
	}else{
		 tippopup("#mobile","一个微信号只能登陆一个账号")
	}
	
	
}